home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / grapdrvs / drawln3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-21  |  4.1 KB  |  118 lines

  1. /*****************************************************************************
  2. *   Default 3d line drawing routine common to graphics drivers.             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include "irit_sm.h"
  8. #include "genmat.h"
  9. #include "iritgrap.h"
  10.  
  11. static RealType CurrentPos[3];
  12.  
  13. /*****************************************************************************
  14. * DESCRIPTION:                                                               M
  15. * A move to command in 3D object space.                         M
  16. *                                                                            *
  17. * PARAMETERS:                                                                M
  18. *   Pt:       Location to move to.                                           M
  19. *                                                                            *
  20. * RETURN VALUE:                                                              M
  21. *   void                                                                     M
  22. *                                                                            *
  23. * KEYWORDS:                                                                  M
  24. *   IGMoveTo3D                                                               M
  25. *****************************************************************************/
  26. void IGMoveTo3D(RealType *Pt)
  27. {
  28.     MatMultVecby4by4(CurrentPos, Pt, IGGlblCrntViewMat);
  29.     IGMoveTo2D(CurrentPos[0], CurrentPos[1]);
  30. }
  31.  
  32. /*****************************************************************************
  33. * DESCRIPTION:                                                               M
  34. * A line to command in 3D object space.                         M
  35. *                                                                            *
  36. * PARAMETERS:                                                                M
  37. *   Pt:       Location to draw to.                                           M
  38. *                                                                            *
  39. * RETURN VALUE:                                                              M
  40. *   void                                                                     M
  41. *                                                                            *
  42. * KEYWORDS:                                                                  M
  43. *   IGLineTo3D                                                               M
  44. *****************************************************************************/
  45. void IGLineTo3D(RealType *Pt)
  46. {
  47.     RealType NewPos[3];
  48.  
  49.     MatMultVecby4by4(NewPos, Pt, IGGlblCrntViewMat);
  50.  
  51.     if (IGGlblDepthCue) {
  52.     if (CurrentPos[2] <= 0.0 && NewPos[2] <= 0.0) {
  53.         if (IGGlblIntensityHighState)
  54.         IGSetColorIntensity(FALSE);
  55.  
  56.         IGLineTo2D(NewPos[0], NewPos[1]);
  57.     }
  58.     else if ((CurrentPos[2] >= 0.0 && NewPos[2] >= 0.0) ||
  59.          ABS(CurrentPos[2] - NewPos[2]) < EPSILON) {
  60.         if (!IGGlblIntensityHighState)
  61.         IGSetColorIntensity(TRUE);
  62.  
  63.         IGLineTo2D(NewPos[0], NewPos[1]);
  64.     }
  65.     else {                      /* Line intersect Z = 0 plane. */
  66.         RealType MidPos[3],
  67.         t = CurrentPos[2] / (CurrentPos[2] - NewPos[2]);
  68.  
  69.         MidPos[0] = CurrentPos[0] * (1.0 - t) + NewPos[0] * t;
  70.         MidPos[1] = CurrentPos[1] * (1.0 - t) + NewPos[1] * t;
  71.  
  72.         if (IGGlblIntensityHighState) {
  73.         if (CurrentPos[2] > 0.0) {
  74.             IGLineTo2D(MidPos[0], MidPos[1]);
  75.         }
  76.         else {
  77.             IGLineTo2D(NewPos[0], NewPos[1]);
  78.             IGMoveTo2D(MidPos[0], MidPos[1]);
  79.         }
  80.  
  81.         IGSetColorIntensity(FALSE);
  82.  
  83.         if (CurrentPos[2] > 0.0) {
  84.             IGLineTo2D(NewPos[0], NewPos[1]);
  85.         }
  86.         else {
  87.             IGLineTo2D(CurrentPos[0], CurrentPos[1]);
  88.             IGMoveTo2D(NewPos[0], NewPos[1]);
  89.         }
  90.         }
  91.         else {
  92.         if (CurrentPos[2] < 0.0) {
  93.             IGLineTo2D(MidPos[0], MidPos[1]);
  94.         }
  95.         else {
  96.             IGMoveTo2D(NewPos[0], NewPos[1]);
  97.             IGLineTo2D(MidPos[0], MidPos[1]);
  98.         }
  99.  
  100.         IGSetColorIntensity(TRUE);
  101.  
  102.         if (CurrentPos[2] < 0.0) {
  103.             IGLineTo2D(NewPos[0], NewPos[1]);
  104.         }
  105.         else {
  106.             IGLineTo2D(CurrentPos[0], CurrentPos[1]);
  107.             IGMoveTo2D(NewPos[0], NewPos[1]);
  108.         }
  109.         }
  110.     }
  111.     }
  112.     else {
  113.     IGLineTo2D(NewPos[0], NewPos[1]);
  114.     }
  115.  
  116.     GEN_COPY(CurrentPos, NewPos, 3 * sizeof(RealType));
  117. }
  118.